package main

import "fmt"

///  Dog 采用继承的方式继承与Animal 拥有animal的方法和成员变量
/// 运行结果如下：
//alex is sleeping
//alex is running
//dog.Name=alex
//call Animal inside

// Animal 结构体
type Animal struct{
	Name string
	Age int
}

// Sleep Animal类型的Sleep方法
func (a *Animal) Sleep(){
	fmt.Printf("%v is sleeping\n", a.Name)
}

// 基类的内部函数调用测试
func (a* Animal) inside() {
	fmt.Printf("call Animal inside\n")
}

// Dog 结构体
type Dog struct{
	Feet int
	*Animal    // 匿名嵌套结构体指针！！类似于继承
}

// Run Dog类型 的 Run方法
func (d *Dog) Run(){
	fmt.Printf("%v is running\n", d.Name)
}

func main(){
	dog := &Dog{
		Feet:   4,
		Animal: &Animal{      // 注意！！嵌套的是指针 ！！
			Name: "alex",
			Age:  3,
		},
	}
	dog.Sleep()   // alex is sleeping
	dog.Run()     // alex is running
	fmt.Printf("dog.Name=%s\n", dog.Name)
	dog.inside()
}